package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.base.Image;
import com.hdax.dm.mappers.ImageMapper;
import com.hdax.dm.service.ImageService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ImageServiceImpl extends ServiceImpl<ImageMapper, Image> implements ImageService {

    @Override
    public Image image(Long targetId, Long type, Long category) {
        QueryWrapper<Image> wrapper = new QueryWrapper<>();
        wrapper.eq("targetId",targetId);
        wrapper.eq("type",type);
        wrapper.eq("category",category);
        return getOne(wrapper);
    }

    @Override
    public CommonResponse<List<Image>> imageCarousels() {
        QueryWrapper<Image> wrapper = new QueryWrapper<>();
        wrapper.eq("type",1L);
        IPage<Image> iPage = page(Page.of(1L,3L),wrapper);
        return ResponseUtils.returnSuccess(iPage.getRecords());
    }
}
